package com.wbcs.config.database.datasource;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jf.plugin.activerecord.DbKit;
import com.wbcs.config.database.datasource.AbsDataSource;
import com.wbcs.exception.WbcsRuntimeException;

/**
 * @author hawkfly
 */
public class JbsfDataSource extends AbsDataSource {
	
	 private static Log log=LogFactory.getLog(JbsfDataSource.class);
	private DataSource ds;
	
	public JbsfDataSource(){
		this.ds = DbKit.getConfig().getDataSource();
		log.info("########"+ this.ds.toString()); 
	}

	/* (non-Javadoc)
	 * @see com.wbcs.config.database.datasource.AbsDataSource#getConnection()
	 */
	public Connection getConnection() {
		// TODO Auto-generated method stub
		try {
			log.debug("从数据源" + this.getName() + "获取数据库连接");
            return this.ds.getConnection();
	    } catch (SQLException e) {
	            throw new WbcsRuntimeException("获取" + this.getName() + "数据源的数据库连接失败", e);
	    }
	}

	/* (non-Javadoc)
	 * @see com.wbcs.config.database.datasource.AbsDataSource#getDataSource()
	 */
	public DataSource getDataSource() {
		// TODO Auto-generated method stub
		return this.ds;
	}
}
